/*
	For retrieving path & filenames for selected images (in order):
	
	imageList.getAllNodes().forEach(function(node){
		var item = imageList.getItem(node.id);
		console.log( item.data.path[0] );
	});
*/

function removeImage( nodeid ) {
	imageList.delItem( nodeid );
	dojo.destroy(dojo.byId(nodeid));
}

function imageListCreator( item, hint ) {
	if ( item.data != undefined ) var data = item.data; else var data = item;
	var node_li = document.createElement("li");
	var node_id = dojo.dnd.getUniqueId();
	dojo.attr( node_li, {id: node_id, innerHTML: "<a onclick='removeImage(\""+node_id+"\");return false;' href='#'><img src='bin.png' /></a> "+data.name[0]} );
	var type = "image";
	return { node: node_li, data: data, type: type }                
}

function showImagePreview( item, widget ) {
	dojo.attr( dojo.byId("img_Preview"), "src", item.path[0] );
}

function generateSheet() {
	var paths = [];
	imageList.getAllNodes().forEach(function(node){
		var item = imageList.getItem(node.id);
		paths.push( item.data.path[0] );
	});
	var filestr = paths.join(',');
	dojo.attr( dojo.byId("outputImage"), "src", "create.php?files="+filestr );
	dojo.xhrPost({
		url: "makecss.php",
		handleAs: "json",
		content: { files: filestr },
		load: function(data, ioargs) {
			if ( data.css != undefined ) {
				dojo.attr(dojo.byId("cssOutput"), "innerHTML", data.css);
			}
		},
		error: function(data, ioargs) {
		}
	});
}
